#!/bin/bash

OUTPUT=`uname.bin $*`
NOT_INSTALLED="is not installed"

if [[ $* == "-r" ]];then
    lines=`rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel | wc -l`
    if [ "$lines" -gt 1 ]; then
        echo $OUTPUT
        exit 0
    fi
    dir=`rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel | head -n 1`
    if [ -z "$(echo "$dir" | grep "$NOT_INSTALLED")" ]; then
        [ -n "$dir" ] && echo $dir && exit 0
    fi  
    dir=`rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel-devel | head -n 1`
    if [ -z "$(echo "$dir" | grep "$NOT_INSTALLED")" ]; then
        [ -n "$dir" ] && echo $dir && exit 0
    fi  
    dir=`rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel-headers | head -n 1`
    if [ -z "$(echo "$dir" | grep "$NOT_INSTALLED")" ]; then
        [ -n "$dir" ] && echo $dir && exit 0
    fi  
    echo "error: you must installed kernel or kernel-headers" && exit 1
else
    echo $OUTPUT
fi
